﻿#region License Revision: 0 Last Revised: 6/18/2008 11:00 AM
/******************************************************************************
Copyright (c) Microsoft Corporation.  All rights reserved.


This file is licensed under the Microsoft Public License (Ms-PL). A copy of the Ms-PL should accompany this file. 
If it does not, you can obtain a copy from: 

http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
******************************************************************************/
#endregion // License
// VIEWS Sample
// Common Library for Silverlight Popup
// MS Research 2008
using System;
using System.Windows.Browser;
using System.Text;
using System.Collections.ObjectModel;
using VIEWS;
using SilverlightPopup;

namespace SilverlightMap
{
    /// <summary>
    /// Find Variables with the layer info 
    /// </summary>
    public class FindLayer
    {
        /// <summary>
        /// what we are looking for (i.e. pizza)
        /// </summary>
        private string what;

        /// <summary>
        /// where we are looking for it (i.e. redmond, wa)
        /// </summary>
        private string where;

        /// <summary>
        /// The layer that holds shapes of this type, null if there have been no shapes of this type yet.
        /// </summary>
        private VEShapeLayer layer;

        /// <summary>
        /// The path to the icon file
        /// </summary>
        private string iconPath;

        /// <summary>
        /// a flag that tells if a type is currently visible
        /// </summary>
        private bool fVisible = true;

        /// <summary>
        /// The Find "what" string
        /// </summary>
        public string What
        {
            get { return what; }
            set { what = value; }
        }

        /// <summary>
        /// The Find "where" string
        /// </summary>
        public string Where
        {
            get { return where; }
            set { where = value; }
        }

        /// <summary>
        /// Color of the pins for this find set
        /// </summary>
        public string IconPath
        {
            get { return iconPath; }
            set { iconPath = value; }
        }

        /// <summary>
        /// The layer that holds the results of this find operation.
        /// </summary>
        public VEShapeLayer Layer
        {
            get { return layer; }
            set { layer = value; }
        }

        /// <summary>
        /// a flag that tells if a type is currently visible
        /// we use this so we don't have to necessarily 
        /// </summary>
        public bool Visible
        {
            get { return fVisible; }
            set
            {
                fVisible = value;
                // set the visible attribute on the layer if it's loaded
                if (layer != null)
                    layer.Visible = value;
            }
        }

        /// <summary>
        /// Get the current layer, and if we don't have one yet, create one
        /// </summary>
        /// <param name="map">map</param>
        /// <returns></returns>
        public VEShapeLayer GetLayer(VEMap map)
        {
            if (layer == null)
            {
                layer = new VEShapeLayer();
                map.AddShapeLayer(layer);
            }
            return layer;
        }

        /// <summary>
        /// Get a concatinated string that shows what and/or where
        /// </summary>
        /// <returns>concatenated find string</returns>
        public string GetFindString()
        {
            StringBuilder sb = new StringBuilder();
            bool fWhat = what != null && what.Length > 0;
            bool fWhere = where != null && where.Length > 0;
            if (fWhat)
                sb.Append(what);
            if (fWhere)
            {
                if (fWhat)
                    sb.Append(" - ");
                sb.Append(where);
            }
            return sb.ToString();
        }

        /// <summary>
        /// Create a new FindLayer
        /// </summary>
        /// <param name="st">SensorType</param>
        public FindLayer(string findWhat, string findWhere, VEShapeLayer findLayer, string findIconPath)
        {
            what = findWhat;
            where = findWhere;
            layer = findLayer;
            iconPath = findIconPath;
        }

    }
}
